// pages/screens/info/info.js
const app = getApp();
const serviceUrl = getApp().globalData.serviceUrl;
const regeneratorRuntime = app.globalData.regeneratorRuntime;
var QQMapWX = require("../../../utils/qqmap-wx-jssdk.min.js");
var utils = require("../../../utils/util.js");
const screenservice = require("../../../apiservice/screen/screenservice");
var attachmentservice = require("../../../apiservice/attachment/attachmentservice");
const QQMapKey = getApp().globalData.QQMapKey;
var qqmapsdk;

var sliderWidth = 96; // 需要设置slider的宽度，用于计算中间位置
const icon =
	''
const buttons = [{
		openType: 'update',
		label: '修改',
		icon: "../../../images/pages/new.png",
	},
	{
		openType: 'sign',
		label: '签到',
		icon: "../../../images/pages/search.png",
	},
	{
		openType: 'publish',
		label: '发布',
		icon: "../../../images/pages/stat.png",
	}, {
		openType: 'copy',
		label: '复制',
		icon: "../../../images/pages/stat.png",
	}, {
		openType: 'inactive',
		label: '停用',
		icon: "../../../images/pages/stat.png",
	},
	{
		openType: 'finish',
		label: '完成',
		icon: "../../../images/pages/stat.png",
	},
	{
		openType: 'swich',
		label: '切换',
		icon: "../../../images/pages/stat.png",
	}
]
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		id: "1",
		//结果录入跳转url
		JGLRUrl: "",
		//宣讲跳转url
		ropagandaUrl: "",
		//客户列表跳转url
		accountListUrl: "",
		//浮动按钮配置数据
		types: ['topLeft', 'topRight', 'bottomLeft', 'bottomRight', 'center'],
		typeIndex: 3,
		colors: ['light', 'stable', 'positive', 'calm', 'balanced', 'energized', 'assertive', 'royal', 'dark'],
		colorIndex: 4,
		dirs: ['horizontal', 'vertical', 'circle'],
		dirIndex: 0,
		sAngle: 1,
		eAngle: 360,
		spaceBetween: 10,
		buttons,
		showMore: false,
		source: null,
		screenId: "",
		screenDetail: {},
		screenTemplateTypeValue: 0,
		//结果录入
		resultEntryShow: false,
		//信息采集
		informationCollectionShow: false,
		//筛查宣讲
		screeningPreachShow: false,
		//客户列表
		customerListShow: false,

		headerShow: true,
		//完成
		CarryOutShow: true,
		//点击拍照按钮的模块显示状态
		photoActionHidden: false,
		tempFilePaths: [], //图片路径数组
		imgUrl: serviceUrl + "/api/Attachment?imgName=",
		delPhotoShow: false,
		PhotoShow: true,
		teammember: '',
		animationData: {},
		screenOwnerId:'',
		currUserId:''
	},



	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: async function(options) {
		this.setData({currUserId:app.globalData.userInfo.userid});
		wx.showLoading({
			title: "加载中...."
		})
		//获取定位服务
		qqmapsdk = new QQMapWX({
			key: QQMapKey
		});

		this.setData({
			screenId: options.screenId
		});
		console.log(this.data.screenId);


		this.initalImages(options.screenId);
		await this.GetScreenData(options.screenId);
		var screenOwnerId = this.data.screenDetail.ownerId;
		this.setData({screenOwnerId:screenOwnerId});
		var currentUserId = app.globalData.userInfo.userid;
		this.IfDisplayField(currentUserId, screenOwnerId, this.data.screenDetail.new_screenstate);
		this.initMenuUrl();
		await this.GetScreenTeamMemberByTeamid(this.data.screenDetail.new_screenteamId);
		wx.hideLoading();
	},

	initMenuUrl: function() {
		let pageData = this.data;

		let propagandaUrl = "/pages/accounts/selector/selector?type=propaganda&stateCode=0";
		propagandaUrl += `&source=${pageData.source}&scid=${pageData.screenId}`;
		propagandaUrl +=
			`&ownerid=${pageData.screenDetail.ownerId}&screenitemid=${pageData.screenDetail.new_new_screenitem}`;
		propagandaUrl += `&screentype=${pageData.screenDetail.new_screentype}`;


		let accountListUrl = "/pages/accounts/list/list?"
		accountListUrl += `scid=${pageData.screenId}`;
		accountListUrl += `&screenownerid=${pageData.screenDetail.ownerId}`;
		accountListUrl += `&screentype=${pageData.screenDetail.new_screentype}`;
		accountListUrl += `&screentemplatetype=${pageData.screenTemplateTypeValue}`;
		//校园筛查
		if (pageData.screenDetail.new_screentype == 100000001) {
			propagandaUrl += `&schoolId=${pageData.screenDetail.new_schoolId}`;
			accountListUrl += `&schoolId=${pageData.screenDetail.new_schoolId}`;
		}

		this.setData({
			propagandaUrl,
			accountListUrl
		})
	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {


	},
	
	onUnload:function(){
		this.clearAnimation();
	},

	ScreenPageShow(new_screenstate, new_screentype, new_templatetype) {
		//新建:0  停用:4  发布:1
		if (new_screenstate == 0 || new_screenstate == 1 || new_screenstate == 4) {
			this.setData({
				resultEntryShow: true,
				informationCollectionShow: true,
				screeningPreachShow: true,
				customerListShow: true,
				headerShow: false,
			});

		} else if (new_screenstate == 3 || new_screenstate == 5) { //3为完成，5为进行中
			//社区筛查
			if (new_screentype == 100000000) {
				this.setData({
					source: 3
				})
				//团队模式
				if (new_templatetype == 1) {
					this.setData({
						resultEntryShow: false,
						informationCollectionShow: false,
						screeningPreachShow: false,
						customerListShow: false,
						headerShow: true,
					});
				}
				//单人模式
				else if (new_templatetype == 2) {
					this.setData({
						resultEntryShow: false,
						informationCollectionShow: true,
						screeningPreachShow: true,
						customerListShow: false,
						headerShow: true,
					});
				}
			}
			//校园筛查
			else if (new_screentype == 100000001) {
				this.setData({
					source: 7
				})
				this.setData({
					resultEntryShow: false,
					informationCollectionShow: true,
					screeningPreachShow: false,
					customerListShow: false,
					headerShow: true,
				});
			}
			//大学校园及圈层
			else if (new_screentype == 100000002) {
				this.setData({
					source: 8
				})
				//团队模式
				if (new_templatetype == 1) {
					this.setData({
						resultEntryShow: false,
						informationCollectionShow: true,
						screeningPreachShow: false,
						customerListShow: false,
						headerShow: true,
					});
				}
				//单人模式
				else if (new_templatetype == 2) {
					this.setData({
						resultEntryShow: false,
						informationCollectionShow: true,
						screeningPreachShow: true,
						customerListShow: false,
						headerShow: true,
					});
				}
			}
			//大客户活动
			else if (new_screentype == 100000003) {
				this.setData({
					source: 6
				})
				//团队模式
				if (new_templatetype == 1) {
					this.setData({
						resultEntryShow: false,
						informationCollectionShow: true,
						screeningPreachShow: false,
						customerListShow: false,
						headerShow: true,
					});
				}
				//单人模式
				else if (new_templatetype == 2) {
					this.setData({
						resultEntryShow: false,
						informationCollectionShow: true,
						screeningPreachShow: true,
						customerListShow: false,
						headerShow: true,
					});
				}

			}
			console.log(this.data.headerShow);
		}
	},

	//是否显示完成- 当前用户是否是该活动的负责人
	IfDisplayField(userid, ownerid, screenState) {
		// debugger
		if (screenState == 5) {
			if (userid == ownerid) {
				this.setData({
					CarryOutShow: false,
				});
			} else {
				this.setData({
					CarryOutShow: true,
				});
			}
		}
	},


	//根据screenId获取筛查详细信息
	async GetScreenData(screenId) {
		//debugger;
		try {
			if (screenId != null) {
				var screenData = await screenservice.GetScreenByScreenID(screenId);
				console.log(screenData);
				if (screenData) {
					this.ScreenPageShow(screenData.data.new_screenstate, screenData.data.new_screentype, screenData.data.new_templatetype);
					this.setData({
						screenDetail: screenData.data,
						screenTemplateTypeValue: screenData.data.new_templatetype,
						screenOwnerId: screenData.data.ownerId
					});
				}
				//团队模式
				if (screenData.data.new_templatetype == 1) {
					//debugger;
					//校园筛查
					if (screenData.data.new_screentype == 100000001) {

						var screenData = screenData.data;
						if (screenData.new_schoolId) {
							this.setData({
								JGLRUrl: "../../accounts/studentselector/studentselector?" +
									`scid=${screenData.new_screenId}&stateCode=0&type=result` +
									`&templateid=${screenData.new_checkmenu}&schoolId=${screenData.new_schoolId}` +
									`&screenteamId=${screenData.new_screenteamId}&schoolName=${screenData.new_schoolName}&stage=${screenData.new_stage}`+
									`&ownerid=${screenData.ownerId}`
							});
						} else {
							wx.showToast({
								title: '没有选择学校',
								mask: true,
								icon: "none"
							})
						}

					} else {
						this.setData({
							JGLRUrl: '../../accounts/selector/selector?scid=' + screenData.data.new_screenId +
								'&stateCode=0&type=result&templateid=' + screenData.data.new_checkmenu
						});
					}

				}
				//单人模式
				else if (screenData.data.new_templatetype == 2) {
					//校园筛查
					if (screenData.data.new_screentype == 100000001) {
						var screenData = screenData.data;
						if (screenData.new_schoolId) {
							this.setData({
								JGLRUrl: "../../accounts/studentselector/studentselector?" +
									`scid=${screenData.new_screenId}&stateCode=0&type=result` +
									`&templateid=${screenData.new_checkmenu}&schoolId=${screenData.new_schoolId}` +
									`&screenteamId=${screenData.new_screenteamId}&schoolName=${screenData.new_schoolName}&stage=${screenData.new_stage}`+
									`&ownerid=${screenData.ownerId}`
							});
						} else {
							wx.showToast({
								title: '没有选择学校',
								mask: true,
								icon: "none"
							})
						}

					} else {
						let toUrl = '/pages/screens/result/add/add?new_screenId=' + screenData.data.new_screenId +
							'&new_doctorid=' + screenData.data.ownerId +
							'&new_screenteamId=' + screenData.data.new_screenteamId +
							'&screentype=' + screenData.data.new_screentype
						toUrl += `&screenitemId=${screenData.data.new_new_screenitem?screenData.data.new_new_screenitem:""}`
						this.setData({
							JGLRUrl: toUrl
						});
					}

				}

			}
		} catch (e) {
			console.log(e);
		} finally {
			wx.hideLoading();
		}
	},

	//根据teamid获取筛查小组成员
	async GetScreenTeamMemberByTeamid(teamid) {
		var teammember = await screenservice.GetScreenTeamMemberByTeamid(teamid);
		console.log(teammember);
		this.setData({
			teammember: teammember.data
		});
	},

	GetScreenDataAsync(screenId) {
		var self = this;
		try {
			if (screenId) {
				screenservice.GetScreenByScreenID(screenId).then(function(screenData) {
					console.log(screenData);

					if (screenData) {
						self.ScreenPageShow(screenData.data.new_screenstate, screenData.data.new_screentype, screenData.data.new_templatetype);
						self.setData({
							screenDetail: screenData.data,
							screenTemplateTypeValue: screenData.data.new_templatetype,
							screenOwnerId: screenData.data.ownerId
						});
					}
					//团队模式
					if (screenData.data.new_templatetype == 1) {
						//校园筛查
						if (screenData.data.new_screentype == 100000001) {
							var screenData = screenData.data;
							self.setData({
								JGLRUrl: "../../accounts/studentselector/studentselector?" +
									`scid=${screenData.new_screenId}&stateCode=0&type=result` +
									`&templateid=${screenData.new_checkmenu}&schoolId=${screenData.new_schoolId}` +
									`&screenteamId=${screenData.new_screenteamId}&schoolName=${screenData.arename}`
							});
						} else {
							self.setData({
								JGLRUrl: '../../accounts/selector/selector?scid=' + screenData.data.new_screenId +
									'&stateCode=0&type=result&templateid=' + screenData.data.new_checkmenu
							});
						}

					}
					//单人模式
					else if (screenData.data.new_templatetype == 2) {
						if (screenData.data.new_screentype == 100000001) {
							var screenData = screenData.data;
							self.setData({
								JGLRUrl: "../../accounts/studentselector/studentselector?" +
									`scid=${screenData.new_screenId}&stateCode=0&type=result` +
									`&templateid=${screenData.new_checkmenu}&schoolId=${screenData.new_schoolId}` +
									`&screenteamId=${screenData.new_screenteamId}&schoolName=${screenData.arename}`
							});
						} else {
							self.setData({
								JGLRUrl: '/pages/screens/result/add/add?new_screenId=' + screenData.data.new_screenId +
									'&new_doctorid=' + screenData.data.ownerId + '&screenitemId=' + screenData.data.new_new_screenitem +
									'&new_screenteamId=' + screenData.data.new_screenteamId + '&screentype=' + screenData.data.new_screentype
							});
						}

					}
				});
			}
			wx.hideLoading();
		} catch (e) {
			console.log(e);
		} finally {

		}
	},


	ModeClick: function() {
		var that = this;

		var screenOwnerId = that.data.screenDetail.ownerId;
		var currentUserId = app.globalData.userInfo.userid;
		if (currentUserId == screenOwnerId) {
			wx.showModal({
				title: '提示',
				content: '你确定切换工作模式？',
				success: function(res) {
					if (res.confirm) {
						wx.showLoading({
							title: '加载中',
							mask: true,
						});
						console.log("确定");
						var modeValue = that.data.screenTemplateTypeValue;
						if (modeValue == 1) {
							that.UpdateScreenData("new_templatetype", 2);
						} else if (modeValue == 2) {
							that.UpdateScreenData("new_templatetype", 1);

						}


					} else {
						console.log('取消');
					}
				}
			})
		}
	},
	//发布
	onPublish: function() {
		var that = this;
		wx.showModal({
			title: '提示',
			content: '您确定发布该筛查活动?',
			success: function(res) {
				if (res.confirm) {
					wx.showLoading({
						title: '正在发布',
						mask: true
					})
					that.UpdateScreenData("new_screenstate", 1);
					wx.showToast({
						title: '活动发布成功',
						icon: "success"
					})

				} else {
					console.log('取消');
				}
			}
		})
	},
	//完成
	ScreenStateClick: function() {
		if (this.data.CarryOutShow == false) {
			var that = this;
			wx.showModal({
				title: '提示',
				content: '你确定要执行完成操作？',
				success: function(res) {
					if (res.confirm) {
						console.log("确定");
						that.UpdateScreenData("new_screenstate", 3);
						that.setData({
							CarryOutShow: true,
						});
					} else {
						console.log('取消');
					}
				}
			})
		}
	},
	//停用
	stopHanlder: function() {
		var that = this;
		wx.showModal({
			title: '提示',
			content: '您确定停用该筛查活动？已停用的活动不可再启动',
			success: function(res) {
				if (res.confirm) {
					wx.showLoading({
						title: '正在停用',
						mask: true
					})
					that.UpdateScreenData("new_screenstate", 4);
					wx.showToast({
						title: '活动停用成功',
						icon: "success"
					})

					that.setData({
						showMore: false,
						CarryOutShow: true,
					});
				} else {
					console.log('取消');
				}
			}
		})

	},

	//修改筛查信息-筛查状态或筛查录入模式
	UpdateScreenData(updateField, fieldValue) {
		try {
			// debugger
			var screenData = {};
			var that = this;
			screenData.new_screenid = this.data.screenDetail.new_screenId;
			screenData.new_checkinaddress = this.data.screenDetail.new_checkinaddress;
			if (updateField == "new_screenstate") {
				screenData.new_screenstate = fieldValue;
			} else if (updateField == "new_templatetype") {
				screenData.new_templatetype = fieldValue;
			}
			screenservice.UpdateScreenData(screenData).then(function(result) {
				// debugger
				console.log(result);

				if (updateField == "new_screenstate") {
					that.setData({
						['screenDetail.new_screenstate']: fieldValue,
					});
					that.ScreenPageShow(fieldValue, that.data.screenDetail.new_screentype, that.data
						.screenTemplateTypeValue);
					wx.hideLoading();
				} else if (updateField == "new_templatetype") {
					//改变录入模式时，改变模式显示状态，并再查一次数据库
					that.setData({
						['screenDetail.new_templatetype']: fieldValue,
						screenTemplateTypeValue: fieldValue,
					});
					that.GetScreenDataAsync(that.data.screenId);

				}
			}).catch(function(error) {
				console.log(error);
			})
		} catch (e) {
			console.log(e);
		}
	},

	openMore: function() {
		this.setData({
			showMore: true
		})
	},
	onClose: function() {
		this.setData({
			showMore: false
		})
	},

	openPhotoAction: function(e) {
		console.log(e);
		this.setData({
			photoActionHidden: true
		})
	},

	/**
	 * 关闭拜访目标达成情况窗口
	 */
	onClose: function() {
		this.setData({
			showMore: false
		})
	},
	/**关闭图片action */
	onPhotoClose: function() {
		this.setData({
			photoActionHidden: false
		})
	},

	onPhotoSelect: function(e) {
		var index = e.detail.id;
		if (index == 1) {
			this.openCamera();
		} else if (index == 2) {
			let animation = wx.createAnimation({
				duration: 400,
				timingFunction: 'ease',
			});
			
			this.setData({
				animationData: animation
			})
			
			animation = this.data.animationData;


			//删除图片			
			this.setData({
				delPhotoShow: true,
				photoActionHidden: false
			})

			let next = true;
			//连续动画关键步骤
		    this.clearAnimation();
			let timeNum = setInterval(function() {
				if (next) {
					animation.rotate(50).step()
					next = !next;
				} else {
					animation.rotate(-50).step()
					next = !next;
				}
				this.setData({
					animationData: animation.export(),
					timeNum: timeNum
				})
			}.bind(this), 80);
		}
		console.log(e);
	},
	
	clearAnimation:function(){
		if(this.data.timeNum)
		{
			debugger;
			clearInterval(this.data.timeNum);
			this.setData({
				animationData: {},
				timeNum: ''
			});
		}
	},


	/**上传图片 */
	openCamera: function() {
		var that = this;
		var imgs = this.data.tempFilePaths;
		var token = wx.getStorageSync('token');
		var imageCount = 5;
		if (imgs.length >= imageCount) {
			wx.showToast({
				title: '最多只能选择5张照片',
				icon: 'none',
				duration: 1500,
				success(res) {
					that.setData({
						photoActionHidden: false
					})
				}
			})

			return;
		}
		wx.chooseImage({
			count: imageCount - imgs.length,
			sizeType: ['original', 'compressed'],
			sourceType: ['album', 'camera'],
			success(res) {
				for (var i = 0; i < res.tempFilePaths.length; i++) {
					//debugger
					var imagename = res.tempFilePaths[i].substring(res.tempFilePaths[i].lastIndexOf('/') + 1)
					imgs.push(imagename);
					wx.uploadFile({
						url: serviceUrl + '/api/Attachment/PostAttachment',
						header: {
							'Authorization': 'Bearer ' + token
						},
						filePath: res.tempFilePaths[i],
						formData: {
							entityId: that.data.screenId
						},
						name: 'file',
						success(success) {
							that.setData({
								photoActionHidden: false,
								tempFilePaths: imgs
							})
							//do something
						},
						fail(error) {
							console.log(error);
						}
					})
				};
			}
		});
	},
	//查询图片
	initalImages: function(screenId) {
		var that = this;
		attachmentservice.GetImgAtachments(screenId).then(function(success) {
			that.setData({
				tempFilePaths: success.data
			})
		}).catch(function(ex) {
			console.log(ex);
		})
	},

	/**
	 * 删除图片
	 */
	delPhoto: function(e) {
		var that = this;
		var index = e.currentTarget.dataset.index;
		var imgPath = this.data.tempFilePaths[index];
		var tempFilePaths = this.data.tempFilePaths;
		wx.showModal({
			title: '',
			content: '是否删除该图片？',
			success(res) {
				console.log(res);
				if (res.cancel) return false;
				tempFilePaths.splice(index, 1)
				that.DelAttachment(imgPath);
				that.setData({
					tempFilePaths: tempFilePaths,
					delPhotoShow: false
				})
				that.clearAnimation();
			}
		})
	},
	DelAttachment: function(dir) {
		attachmentservice.DelAttachment(dir).then(function(success) {
			console.log(success.data);
		}).catch(function(ex) {
			console.log(ex);
		})
	},

	//签到
	onCheckIn: function() {
		var that = this;
		var curTime = new Date();
		//把字符串格式转化为日期类
		var starttime = new Date(Date.parse(this.data.screenDetail.new_startdate));
		var endtime = new Date(Date.parse(this.data.screenDetail.new_enddate));
		//进行比较
		if (curTime >= starttime && curTime <= endtime) {
			this.checkIn();
		} else {

			wx.showModal({
				content: '当前时间和筛查活动计划时间不一致，是否确定签到？',
				success(res) {
					console.log(res);
					if (res.cancel) {
						return false;
					} else {
						that.checkIn();
					}

				}
			});
		}
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	},

	//复制
	onCopyScreen: function() {
		var that = this;

		wx.showModal({
			title: '',
			content: '您确定通过复制该筛查活动来新建一条筛查活动?',
			success(res) {
				if (res.confirm) {
					wx.navigateTo({
						url: "../add/add",
						events: {
							// 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
							OpenScreenAddPage: function(data) {

							}
						},
						success: function(res) {
							// 通过eventChannel向被打开页面传送数据
							res.eventChannel.emit('OpenScreenAddPage', {
								data: that.data.screenDetail
							});
							that.setData({
								showMore: false
							})
						}
					});
				} else if (res.cancel) {

				}
			}
		})
	},

	//修改
	modifyHanlder: function(e) {
		var that = this;
		wx.navigateTo({
			url: "../modify/modify?scid=" + this.data.screenDetail.new_screenId,
			success: function() {
				that.setData({
					showMore: false
				})
			}
		});

	},

	onsearchAccount(e) {
		console.log('onsearchAccount', e)
	},

	onscreenStat(e) {
		console.log('onscreenStat', e)
	},

	onChange(e) {
		console.log('onChange', e)
	},
	/**
	 * 获取当前地点、日期签到
	 */
	getMapAddress: function(res, that) {
		that.setData({
			['screenDetail.new_latitude']: res.latitude,
			['screenDetail.new_longitude']: res.longitude,
		})
		qqmapsdk.reverseGeocoder({
			location: {
				latitude: res.latitude,
				longitude: res.longitude
			},
			coord_type: 1,
			success: function(success) {
				console.log(success)
				var address = success.result.address;
				var currentTime = utils.formatTime(new Date());
				that.setData({
					['screenDetail.new_checkinaddress']: address,
					['screenDetail.new_checkintime']: currentTime
				});
				var screen = that.data.screenDetail;
				screenservice.CheckIn(screen).then(function(success) {
					console.log(success);
					that.setData({
						['screenDetail.new_screenstate']: 5,
						CarryOutShow: false,
					})
					wx.hideLoading();
					wx.showToast({
						title: '签到成功',
						icon: 'success',
						duration: 2000
					});
					that.ScreenPageShow(screen.new_screenstate, screen.new_screentype, screen.new_templatetype);

				}).catch(function(ex) {
					console.log(ex);
					wx.hideLoading();
					wx.showToast({
						title: '签到失败',
						icon: 'none',
						duration: 2000
					});
				})
			}
		})

	},
	checkIn: function() {
		var that = this;
		wx.showLoading({
			title: '正在签到...',
			mask: true
		})

		//获取签到位置
		wx.getLocation({
			success: function(res) {
				that.getMapAddress(res, that);
			},
			fail: function() {
				wx.getSetting({
					success: function(res) {
						var statu = res.authSetting;
						if (!statu['scope.userLocation']) {
							wx.showModal({
								title: '是否授权当前位置',
								content: '需要获取您的地理位置，请确认授权',
								success: function(tip) {
									if (tip.confirm) {
										wx.openSetting({
											success: function(data) {
												if (data.authSetting["scope.userLocation"] === true) {
													wx.showToast({
														title: '授权成功',
														icon: 'none',
														duration: 1000
													})
													wx.getLocation({
														success: function(res) {
															that.getMapAddress(res, that);
														}
													})
												} else {
													wx.showToast({
														title: '授权失败',
														icon: 'none',
														duration: 1000
													})
												}
											}
										})
									} else {
										wx.hideLoading();
									}
								}
							})
						}
					},
					fail: function(res) {
						wx.hideLoading();
						wx.showToast({
							title: '调用授权窗口失败',
							icon: 'none',
							duration: 1000
						})
					}
				})
			}
		})
	},
  navigator2JGLRUrl:function(){
    if (this.data.screenDetail.new_screenstate != 5) {
      wx.showToast({
        title: "该筛查状态不在进行中，不能进行结果录入",
        icon: 'none',
        duration: 2000
      });
      return;
    }
    wx.navigateTo({
      url: this.data.JGLRUrl,
    })
  },
  navigator2propagandaUrl:function(){
    if (this.data.screenDetail.new_screenstate != 5) {
      wx.showToast({
        title: "该筛查状态不在进行中，不能进行宣讲",
        icon: 'none',
        duration: 2000
      });
      return;
    }
    wx.navigateTo({
      url: this.data.propagandaUrl,
    })
  },
  navigator2accountListUrl: function () {
    wx.navigateTo({
      url: this.data.accountListUrl,
    })
  },
  navigator2XXCJUrl:function(){
    console.log(this.data.screenDetail);
    if(this.data.screenDetail.new_screenstate!=5){
      wx.showToast({
        title: "该筛查状态不在进行中，不能进行信息采集",
        icon:'none',
        duration: 2000
      });
      return;
    }
    var screenId = this.data.screenDetail.new_screenId;
    let screenItem = this.data.screenDetail.new_new_screenitem;
		let screenteamId = this.data.screenDetail.new_screenteamId;
		let ownerId = this.data.screenDetail.ownerId;
    let url = "/pages/accounts/add/add?new_screenId=" + screenId + "&new_screenteamId=" + screenteamId + "&new_screenitemId="+screenItem + "&ownerid="+ownerId;
    console.log(url);
    wx.navigateTo({
      url:url,
    })
  }
})
